import { useEffect, useState } from 'react';
import { TreeSelect, Button } from 'antd';
import type { TreeSelectProps } from 'antd';
import styles from './index.module.scss'
import { DataNode } from 'rc-tree-select/lib/interface';
import { useDispatch, useSelector } from 'react-redux';
import { set_subject_two ,get_active_two} from '@/store/slice/exam/subject'

function AddOne(props: { treeData: DataNode[] | undefined; }) {
  const dispatch = useDispatch()
  // const [value, setValue] = useState<string>();
  const active_two=useSelector(get_active_two)

 

  const onChange = (newValue: string, title:any) => {
    console.log(newValue);

    // setValue(newValue);
    dispatch(set_subject_two({
      title:title[0],
      value:newValue
    }))
  };

  const onPopupScroll: TreeSelectProps['onPopupScroll'] = (e) => {
    console.log('onPopupScroll', e);
  };

  return (
    <div className={styles.addOne}>
      <div className={styles.title}>{active_two.title ?active_two.title : 'xxx'}</div>
      <TreeSelect
        showSearch
        style={{ width: '20%' }}
        value={active_two.value}
        styles={{
          popup: { root: { maxHeight: 400, overflow: 'auto' } },
        }}
        placeholder="请选择"
        allowClear
        treeDefaultExpandAll
        onChange={onChange}
        treeData={props.treeData}
        onPopupScroll={onPopupScroll}
      />

      <Button type="primary" > 新增题目</Button>
    </div>

  );
};
export default AddOne;